package com.example.design.dutychain;

import com.example.design.pojo.BusinessLaunch;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

//责任链模式具体责任类
public class ProductHandler extends AbstractBusinessHandler{
    @Override
    public List<BusinessLaunch> processHandler(List<BusinessLaunch> launchList, String targetCity, String targetSex, String targetProduct) {
        if (launchList.isEmpty()){
            return launchList;
        }
        launchList.stream().filter(launch ->{
            String product = launch.getTargetProduct();
            if (StringUtils.isEmpty(product)){
                return true;
            }
            List<String> list = Arrays.asList(product.split(","));
            return list.contains(targetProduct);
        });
        if (hasNextHandler()){
            return nextHandler.processHandler(launchList,targetCity,targetSex,targetProduct);
        }
        return launchList;
    }
}
